<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>公告信息</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <style>
        .nx-nav-container ul{
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }

        .nx-nav-container ul li{
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }

        .nx-nav-container a{
            color: #FFFFFF;
        }

        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }

        td {
            vertical-align: middle! important;
        }

        #notice-box li{
            margin-bottom: 10px;
        }
        #view-notice-body img {
            width:400px;
        }
        #view-notice-body iframe{
            width:400px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div class="nx-header">
        <div style="display: flex;width: 100%;height: 30px;line-height: 30px;background-color: #eee;">
            <div style="flex: 5;padding: 0 10px; color: orangered;">
                欢迎访问 电影订票购票系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您： {{user.name}}
                <a style="margin-left: 30px;color: blue;" href="javascript:void(0);" @click="logout">退出</a>
            </div>
        </div>
    </div>

    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px;position: relative;">
            <img src="img/logo1.png" style="width: 40px;position: absolute;top: 20px;">
            <b style="margin-left: 45px;font-size:25px;text-shadow: 5px 5px 3px #888888">电影订票购票系统</b>
        </div>
    </div>

    <div class="nx-nav-container" style="height: 45px;background-color: black;">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li class="active"><a href="advertiserInfo.html">公告信息</a></li>
            <li><a href="messageInfo.html">在线交流信息</a></li>
            <li><a href="linkInfo.html">友情链接</a></li>
            <li><a href="cartInfo.html">收藏栏信息</a></li>
            <li><a href="orderInfo.html">订单信息</a></li>
            <li><a href="commonInfo.html">评价信息</a></li>
            <li><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li v-if="!isLogin"><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li v-if="!isLogin"><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>

    <div class="container" style="margin-top: 20px;">
        <div class="row">
            <div class = "col-md-8">
                <div class = "panel panel-default">
                    <div class="panel-heading">
                        <b>{{currentAdvertiser.name}}</b>
                        <span style = "float: right;color: #888888">{{currentAdvertiser.time}}</span>
                    </div>
                    <div class="panel-body" id="view-notice-body" v-html="currentAdvertiser.content"></div>
                </div>
            </div>
            <div class = "col-md-4">
                <div class = "panel panel-default" id ="notice-box">
                    <div class="panel-heading">
                        <b>公告列表</b>
                    </div>
                    <div class="panel-body">
                        <ul id = "notice-item-box">
                            <li v-for = "item in advertiserList">
                                <a :href="'advertiserInfo.html?id ='+item.id" v-bind:class="{active: item.isActive}">{{item.name}}</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
         </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/swiper-5.4.5/swiper.min.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>
<script>
    new Vue({
        el: "#wrapper",
        data: {
            user: {},           // 当前登录用户
            isShow: false,      // 是否显示进入后台
            isLogin: false,     // 是否登录
            advertiserList:[],  //最新的十条公告
            currentId:0,        //当前展示的公告id
            currentAdvertiser:{}//当前公告详情
        },
        created: function () {
            // 查询权限
            axios.get('/auth').then(res => {
                if (res.data.code == '0') {
                    this.user = res.data.data;
                    // 若是管理员
                    if (this.user.level === 1) {
                        // 显示可以进入后台
                        this.isShow = true;
                    }
                    this.isLogin = true;
                }
            });
            this.currentId =this.getQueryVariable('id');
            this.loadAdvertiserInfo();
        },
        methods: {
            //加载公告列表
            loadAdvertiserInfo(){
                axios.get("/advertiserInfo/page/all?pageSize=10" ).then(res => {
                    if (res.data.code === '0') {
                        this.advertiserList = res.data.data.list;
                        if(this.currentId===''){
                            this.currentId = this.advertiserList[0].id;
                        }
                        this.advertiserList = forEach(item =>{
                            if(parseInt(this.currentId) === item.id) {
                                item.isActive = true;
                                this.currentAdvertiser = item;
                            }else{
                                item.isActive = false;
                            }
                        });
                    } else {
                        alert(res.data.msg);
                    }
                });
            },
            //获取前一页传来的参数
            getQueryVariable(variable){
                let query = window.location.search.substring(1);
                let vars = query.split("&");
                for(let i=0;i<vars.length;i++){
                    let pair = vars[i].split("=");
                    if(pair[0] === variable){
                        return pair[1];
                    }
                }
                return '';
            },

            logout(){
                axios.get('/logout').then(res =>{
                    if(res.data.code === '0'){
                        location.href = '/front/index.html';
                    }else{
                        alert(res.data.msg);
                    }
                });
            },
        }
    });
</script>
</body>
</html>
